<!--
 * @Author: wwssaabb
 * @Date: 2021-07-20 11:17:14
 * @LastEditTime: 2021-07-20 11:20:06
 * @FilePath: \demo\react_demo\demo\base_demo\函数组件使用props.html
-->

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="test1"></div>
  <div id="test2"></div>
  <div id="test3"></div>

  <script type="text/javascript" src="../js/react.development.js" ></script>
  <script type="text/javascript" src="../js/react-dom.development.js" ></script>
  <script type="text/javascript" src="../js/babel.min.js" ></script>
  <script type="text/javascript" src="../js/prop-types.js" ></script>
  <script type="text/babel">  /* JSX 语法用babel转换 */

    function Person(props){
      const {name,sex,age} = props
        return (
          <ul>
            <li>姓名：{name}</li>
            <li>性别：{sex}</li>
            <li>年龄：{age}</li>
          </ul>
        )
    }
    
    Person.propTypes = {
      name:PropTypes.string.isRequired,
      sex:PropTypes.string,
      age:PropTypes.number
    }
    //对标签属性进行默认值的设置
    Person.defaultProps={
      sex:'未知',
      age:18
    }

    let p1={name:'tom',sex:'女',age:18}
    let p2={name:'joker',sex:'男',age:19}
    let p3={name:'tony',sex:'女',age:16}
    
    ReactDOM.render(<Person {...p1}/>,document.getElementById('test1'))
    ReactDOM.render(<Person {...p2}/>,document.getElementById('test2'))
    ReactDOM.render(<Person {...p3}/>,document.getElementById('test3'))


  </script>
</body>
</html>